using System;
using System.Collections.Generic;
using System.Text;
using Ent.Log;
using System.Configuration;
using System.Web;

namespace Ent.Voice
{
    public class Global
    {
        public const string UserAgreement = "UserAgreement";
        //TODO
        public static object[] Search(int catId, int eventId, string key, int startIndex, int rowcount, string Event_orderby, string Entry_orderby, string User_orderby, bool includeSuspended, string viewId, ref int total)
        {
            int eventCount = 0;
            int entryCount = 0;
            int userCount = 0;
            int count = rowcount / 3;
            object[] retValue = new object[] { Ent.Voice.Nomination.Entry.Search(Ent.Voice.Nomination.EntryFilter.Event, eventId.ToString(), key, startIndex, count, Entry_orderby, includeSuspended, viewId, ref entryCount), 
                Ent.Voice.Show.Event.Search(catId, key, startIndex, count, Event_orderby, ref eventCount), 
                Ent.Voice.User.Search(key, startIndex, count, User_orderby, ref userCount) };
            total = eventCount + entryCount + userCount;
            return retValue;
        }
        public static Logger Log
        {
            get
            {
                Logtype type = (Logtype)Enum.Parse(typeof(Logtype), ConfigurationManager.AppSettings["LogLevel"]);
                string logPath = ConfigurationManager.AppSettings["LogPath"];
                return Logger.GetLogger(HttpRuntime.AppDomainAppPath + "/" + logPath, "default", type);
            }
        }
        public static List<KeyValuePair<string, string>> ParseKeyValueText(string text)
        {
            List<KeyValuePair<string, string>> retValue = new List<KeyValuePair<string, string>>();
            string[] kvList = text.Split(new string[] { "$,$" }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string kv in kvList)
            {
                string[] kvItem = kv.Split(new string[] { "$:$" }, StringSplitOptions.RemoveEmptyEntries);
                if (kvItem.Length == 2)
                {
                    retValue.Add(new KeyValuePair<string, string>(kvItem[0], kvItem[1]));
                }
            }
            return retValue;
        }
    }
}
